package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.LunBoTu;
import com.ysd.entity.User;
import com.ysd.util.DBManger;

public class UserDaoImpl {
	//增删改时，应该返回数据库受影响行数
	
	//应该返回数据库受影响行数
	
	public int addMessage(User user) {
		return DBManger.executeUpdate("insert into user values('"+user.getUsername()+"','"+user.getPhone()+"','"+user.getEmail()+"','"+user.getContent()+"')");
	}
	
	
	public List<User> getLYBList(){
		List<User> list = new ArrayList<User>();
		Connection conn=DBManger.getConnection();
		Statement st=null;
		ResultSet rs=null;
		
		try {
			st=conn.createStatement();
			rs=st.executeQuery("select * from User");
			while(rs.next()) {
				String username =rs.getString("username");
				String phone = rs.getString("phone");
				String email = rs.getString("email");
				String content = rs.getString("content");
				String zhuangTai = rs.getString("zhuangTai");
				User lyb=new User(username, phone, email, content, zhuangTai);
				list.add(lyb);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			DBManger.closeAll(conn, st, rs);
		}
	}
}
